
import CameraManager from "../game/CameraManager";
import GameManager from "../game/GameManager";
import Constants from "../libs/Constants";
import GameData from "../libs/GameData";
import Helper from "../libs/HelperMgr";

const {ccclass, property} = cc._decorator;

@ccclass
export default class UIGame extends cc.Component {


    @property(cc.Label)
    model: cc.Label = null;

    @property(cc.Label)
    score: cc.Label = null;

    @property(cc.Label)
    gold: cc.Label = null;

    @property(cc.Label)
    chance: cc.Label = null;

    @property(cc.Label)
    time: cc.Label = null;


    @property(cc.Node)
    mask: cc.Node = null;
   
    // onLoad () {}

    start () {
        this.model.string = GameData.instance.gameModel ? "第" + GameData.instance.gameStage + "关" : "畅意模式";
        this.chance.node.parent.active = GameData.instance.gameModel;
        this.time.node.parent.active = !GameData.instance.gameModel;
    }

    update (dt) {
        if(GameManager.instace.gameIsStart && !GameManager.instace.gameIsOver){
            this.mask.active = CameraManager.instance.isFollowing;
            this.gold.string = GameData.instance.playGold.toString();
            this.score.string = GameManager.instace.gameScore.toString();
            this.chance.string = GameManager.instace.gameChance.toString();
            this.time.string = GameManager.instace.gameTime > 0 ? GameManager.instace.gameTime.toString() : "0";
        }
    }

    public onRank(){
        Helper.showUI(Constants.UIName.UIRank)
    }

    public onTool(){
        if(GameManager.instace.playerIsStosh){
            GameManager.instace.playerIsStosh = false;
            return;
        }
        if(GameData.instance.playStoshs[GameData.instance.playStosh-1] > 0){
            GameManager.instace.playerIsStosh = true;
        }else{
            Helper.showUI(Constants.UIName.UIShop)
        }
    }

    public onBack(){
        GameManager.instace.backMain();
    }
}
